package com.mgy.db.common.query;

import lombok.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * (Notepad)实体查询类
 *
 * @author maguoyong
 * @since 2020-01-29 12:07:32
 */
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class NotepadQuery extends BaseQuery {

    private static final long serialVersionUID = -93793868551503795L;


    /**
     * ${column.comment}
     */
    private Integer id;

    /**
     * ${column.comment}
     */
    private Integer userId;

    /**
     * ${column.comment}
     */
    private String title;

    /**
     * ${column.comment}
     */
    private String content;

    /**
     * ${column.comment}
     */
    private Long tagId;
    private Date createdEqual;
    /**
     * ${column.comment}
     */
    private Date createdStart;
    /**
     * ${column.comment}
     */
    private Date createdEnd;

    private Date modifiedEqual;
    /**
     * ${column.comment}
     */
    private Date modifiedStart;
    /**
     * ${column.comment}
     */
    private Date modifiedEnd;


    @Builder.Default
    private List<OrderField> orderFields = new ArrayList<OrderField>();

    /**
     * 设置排序按属性：id
     *
     * @param isAsc 是否升序，否则为降序
     */
    public void orderbyId(boolean isAsc) {
        orderFields.add(new OrderField("id", isAsc ? "asc" : "desc"));
    }

    /**
     * 设置排序按属性：userId
     *
     * @param isAsc 是否升序，否则为降序
     */
    public void orderbyUserId(boolean isAsc) {
        orderFields.add(new OrderField("user_id", isAsc ? "asc" : "desc"));
    }

    /**
     * 设置排序按属性：title
     *
     * @param isAsc 是否升序，否则为降序
     */
    public void orderbyTitle(boolean isAsc) {
        orderFields.add(new OrderField("title", isAsc ? "asc" : "desc"));
    }

    /**
     * 设置排序按属性：content
     *
     * @param isAsc 是否升序，否则为降序
     */
    public void orderbyContent(boolean isAsc) {
        orderFields.add(new OrderField("content", isAsc ? "asc" : "desc"));
    }

    /**
     * 设置排序按属性：tagId
     *
     * @param isAsc 是否升序，否则为降序
     */
    public void orderbyTagId(boolean isAsc) {
        orderFields.add(new OrderField("tag_id", isAsc ? "asc" : "desc"));
    }

    /**
     * 设置排序按属性：created
     *
     * @param isAsc 是否升序，否则为降序
     */
    public void orderbyCreated(boolean isAsc) {
        orderFields.add(new OrderField("created", isAsc ? "asc" : "desc"));
    }

    /**
     * 设置排序按属性：modified
     *
     * @param isAsc 是否升序，否则为降序
     */
    public void orderbyModified(boolean isAsc) {
        orderFields.add(new OrderField("modified", isAsc ? "asc" : "desc"));
    }

    public class OrderField {
        private String fieldName;
        private String order;
        public OrderField(String fieldName, String order) {
            super();
            this.fieldName = fieldName;
            this.order = order;
        }

        public String getFieldName() {
            return fieldName;
        }

        public void setFieldName(String fieldName) {
            this.fieldName = fieldName;
        }

        public String getOrder() {
            return order;
        }

        public void setOrder(String order) {
            this.order = order;
        }
    }

}